package com.lu;

import java.lang.reflect.Field;

public class mian {

	public static void main(String[] args) throws NoSuchFieldException, SecurityException, ClassNotFoundException {

		/*
		 * 获取Class对象方法一：对象.getClass()
		 */
		// 返回String的class

		Class c = "foo".getClass();
		System.out.println(c);
		//
		Class c1 = System.out.getClass();
		System.out.println(c1);

		Class c2 = E.A.getClass();
		System.out.println(c2);

		byte[] bytes = new byte[1024];
		Class c3 = bytes.getClass();
		System.out.println(c3);

		/*
		 * 获取Class对象方法二：类.class
		 */
		Class c4 = boolean.class; // correct
		System.out.println(c4);
		Class c5 = java.io.PrintStream.class;
		System.out.println(c5);
		Class c6 = int[][][].class;
		System.out.println(c6);
		/*
		 * 获取Class对象方法二：类.class
		 */
		Class c7 = Class.forName("[[Ljava.lang.String;");
		System.out.println(c7);
		/*
		 * 原生类型的包装类 :类.Type
		 */

		Class c8 = Double.TYPE;
		System.out.println(c8);
		Class c9 = Void.TYPE;
		System.out.println(c9);

		// 返回父类
		Class c10 = javax.swing.JButton.class.getSuperclass();
		System.out.println(c10);
		// 返回公开的成员内部类，接口或者是枚举
		Class<?>[] c11 = Character.class.getClasses();
		for (Class<?> class1 : c11) {
			System.out.println("-----" + class1);
		}
		// 返回申明的成员内部类，接口或者是枚举
		Class<?>[] c12 = Character.class.getDeclaredClasses();
		for (Class<?> class1 : c12) {
			System.out.println("-----" + class1);
		}

		// 获取申明该变量的类
		Field f = System.class.getField("out");
		Class c13 = f.getDeclaringClass();
		System.out.println(c13);
		// 返回包裹该类的类
		Class c14 = Thread.State.class.getEnclosingClass();
		System.out.println(c14);

	}
}
